using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using System.Linq;

    
    public sealed class CpuPerformance<T> : FeatureBase<object>
    {
        public CpuPerformance(){}

        public CpuPerformance(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Cpu performance"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Engine; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.CpuPerformance; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_TF; } }

        public override bool IsRounded
        {
            get { return false; }
        }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;
            
            var temp = (double) Value *
                // Bonus from extensions
                (1 + agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType)) *
                // Bonus from Coprocessors modules
                (1 + robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType, ModuleGroupsEnum.Coprocessors));

            ModifiedValue = IsRounded
                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                : Math.Round(temp, 2);
        }

        /// <summary>
        /// Obtains the feature modified or base value with the unit
        /// </summary>
        public override string FormattedValue
        {
            get { return String.Format("{0} {1}", Math.Round((double)(IsModified ? ModifiedValue : Value),0), Unit); }
        }
    }
}